<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/25
 * Time: 15:22
 */

namespace app\admin\controller;

use app\model\CourierInfo as ModelCourierInfo;
use app\model\CourierOrder as ModelCourierOrder;
use app\model\UserOrder as ModelUserOrder;
use app\model\UserOrderLog as ModelUserOrderLog;
use app\model\StationOrder as ModelStationOrder;
use app\model\Express as ModelExpress;
use app\model\DriverOrder as ModelDriverOrder;
use app\model\ApplyForSettled as ModelApplyForSettled;
use app\model\AdminInfo as ModelAdminInfo;
use app\logic\Excel as MobileLogicExcel;


class Courier extends Member
{
    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 快递员信息详情
     * uri:/admin/curier.details
     */
    public function curierDetails(){
        $arr_where = [];

        $curierId = $this->_getContentParams('courierId');
        _toValidate('id',$curierId,10009);
        //$curierId = 2;
        if (!empty($curierId)){
            $arr_where['courier_info.id'] = $curierId;
        }
        $block = $this->_getContentParams('block');
        _toValidate('id',$block,10823);
        //$block = 1;
        switch ($block){
            case 1://快递员详情
                $list = ModelCourierInfo::getInstance()->getCourierDetail($arr_where);
                _returnData(['courierDetails'=>$list]);
                break;
            case 2://统计信息
                $list = ModelCourierInfo::getInstance()->getCourierStatistical($arr_where);
                _returnData(['statistical'=>$list]);
                break;
            default:
                break;
        }
    }

    /**
     * 快递员订单列表
         * uri:/admin/courier.orderList
     */
    public function courierOrderList(){
        $courierId = $this->_getContentParams('courierId');
        //$orderState = $this->_getContentParams('orderState');
        //$courierId =25;
//        $orderState =null;
        $int_now_page = $this->_getContentParams('page'); // 当前页码
        if (empty($int_now_page)){
            $int_now_page = 1;
        }
        _toValidate('id', $int_now_page, 10005);

        $int_list_rows = $this->_getContentParams('listRows'); // 一页的条数
        if (empty($int_list_rows)){
            $int_list_rows = 10;
        }
        _toValidate('id', $int_list_rows, 10006);

        $sort = $this->_getContentParams('sort');
        _toCompare(empty($sort),'==',true,20012);

        $arr_where = '';

        $arr_where.="courier_order.courier_id=$courierId and courier_order.state in (20,25,30,40,70,75,80,90)";
        if (!empty($orderState)){
            $arr_where.=" and courier_order.state=$orderState";
        }
        $orderNumber = $this->_getContentParams('orderNumber');
        $startTime = $this->_getContentParams('startTime');
        $endTime = $this->_getContentParams('endTime');
        if(!empty($orderNumber)){
            $arr_where.=" and (user_order.order_sn like '%$orderNumber%' or user_order.express_order_sn like '%$orderNumber%')";
        }

        if (!empty($startTime)){
            $arr_where.=" and DATE_FORMAT(courier_order.gmt_create,'%Y%m%d') >= DATE_FORMAT('$startTime','%Y%m%d')";
        }

        if (!empty($endTime)){
            $arr_where.=" and DATE_FORMAT(courier_order.gmt_create,'%Y%m%d') <= DATE_FORMAT('$endTime','%Y%m%d')";
        }

        $int_total_rows = ModelCourierOrder::getInstance()->getToCount($arr_where,1);
        $int_total_pages = (int)ceil($int_total_rows / $int_list_rows);//总页数
        _toCompare(($int_now_page > $int_total_pages && $int_total_pages > 0), '===', true, 10007);
        $int_first_row = $int_list_rows * ($int_now_page - 1);//从第几条开始查询

        $list = ModelCourierOrder::getInstance()->getCourierOrderList($arr_where,'courier_order.courier_id as courierId,courier_order.order_id as orderId,user_order.order_sn as orderSn,user_order.express_order_sn as expressOrderSn,courier_order.gmt_create as gmtCreate,user_order.order_amount as orderAmount,user_order.protect_price as protectPrice,courier_order.state',$int_first_row,$int_list_rows,'1',$sort);
        _returnData(['totalPages' => $int_total_pages,'courierInfoList'=>$list]);
    }


    /**
     * 快递员资料编辑
     * uri:/admin/courier.editData
     */
    public function editData(){
        $courierId = $this->_getContentParams('courierId');
        _toValidate('id',$courierId,10009);
        //$courierId =2;
        $arr_where['courier_info.id'] = $courierId;
        $list = ModelCourierInfo::getInstance()->getEditData($arr_where);
        _returnData(['editData'=>$list]);
    }

    /**
     * 快递员订单详情
     * uri:/admin/courier.orderDetails
     */
    public function courierOrderDetails(){
        $orderState=null;
        $orderUserInfo=null;
        $costInformation=null;
        $basicInfo=null;
        $closed=null;
        $putInStorage=null;
        $driverInfo=null;
        $outbound=null;
        $send=null;
        $operationInfo=null;
        $orderId = $this->_getContentParams('orderId');
        _toValidate('id',$orderId,10009);
        //$orderId = 90;
        $arr_where=['user_order.order_id'=>$orderId];
        //订单状态
        $orderState = ModelCourierOrder::getInstance()->toValue("order_id=$orderId",'state');
        //下单人信息
        $orderUserInfo = ModelUserOrder::getInstance()->getUserOrderInfo($arr_where);
        //费用信息
        $costInformation = ModelUserOrder::getInstance()->toFind("order_id=$orderId",'first_heavy_fee AS firstHeavyFee,other_heavy_fee AS otherHeavyFee,protect_price AS protectPrice,order_amount AS orderAmount');
        //基本信息
        $basicInfo = ModelUserOrder::getInstance()->toFind("order_id=$orderId",'order_sn AS orderSn,express_order_sn AS expressOrderSn,gmt_create AS gmtCreate,door_time AS doorTime,item_price AS itemPrice,item_type AS itemType,item_weight AS itemWeight,package,sender_info AS senderInfo,recipient_info AS recipientInfo');
        $basicInfo['describe'] = ModelUserOrderLog::getInstance()->toValue("order_id=$orderId",'describe','gmt_create desc');
        //收件快递员
        $closed = ModelCourierOrder::getInstance()->getCourierInfo("courier_order.order_id=$orderId and courier_order.is_pick=1");
        //派件快递员
        $send = ModelCourierOrder::getInstance()->getCourierInfo("courier_order.order_id=$orderId and courier_order.is_pick=2");
        //发件站点
        $putInStorage = ModelStationOrder::getInstance()->getStationInfo("station_order.order_id=$orderId and station_order.is_pick=1");
        if ($putInStorage){
            $courierCompanyName = ModelExpress::getInstance()->getExpressName("express_id={$putInStorage['express_id']}");
            $putInStorage['courierCompanyName']=$courierCompanyName;
            //司机信息
            $driverInfo = ModelDriverOrder::getInstance()->getDriverInfo("driver_order.box_id={$putInStorage['boxOrderNumber']}");
            if ($driverInfo){
                $courierCompanyName = ModelExpress::getInstance()->getExpressName("express_id={$driverInfo['express_id']}");
                $driverInfo['courierCompanyName'] = $courierCompanyName;
            }
        }
        //收件站点
        $outbound = ModelStationOrder::getInstance()->getStationInfo("station_order.order_id=$orderId and station_order.is_pick=2");
        if ($outbound){
            $courierCompanyName = ModelExpress::getInstance()->getExpressName("express_id={$outbound['express_id']}");
            $outbound['courierCompanyName']=$courierCompanyName;
        }

        //操作信息
        $operationInfo = ModelUserOrderLog::getInstance()->toSelect("order_id=$orderId",'operator,mobile,gmt_create AS gmtCreate,pay_state AS payState,order_state_display AS orderStateDisplay,remark','','','gmt_create desc');
        _returnData(['orderState'=>$orderState,'orderUserInfo'=>$orderUserInfo,'costInformation'=>$costInformation,'basicInfo'=>$basicInfo,'closed'=>$closed,'putInStorage'=>$putInStorage,'driverInfo'=>$driverInfo,'outbound'=>$outbound,'send'=>$send,'operationInfo'=>$operationInfo]);


    }

    /**
     * 快递员资料编辑修改
     * uri:/admin/courier.editDataUpdate
     */
    public function courierEditDataUpdate(){
        $courierId = $this->_getContentParams('courierId');
        _toValidate('id',$courierId,10009);
        $account = $this->_getContentParams('account');
        $realName = $this->_getContentParams('realName');
        $idNumber = $this->_getContentParams('idNumber');
        $startTerm =$this->_getContentParams('startTerm');
        $endTerm = $this->_getContentParams('endTerm');
        $idcardFront = $this->_getContentParams('idcardFront');
        $idcardBack = $this->_getContentParams('idcardBack');
        $headPortrait = $this->_getContentParams('headPortrait');
        $express = $this->_getContentParams('express');
        $expressBranch = $this->_getContentParams('expressBranch');
        $jobNumber = $this->_getContentParams('jobNumber');
        $workCard = $this->_getContentParams('workCard');
        $address = $this->_getContentParams('address');
        $isEnable = $this->_getContentParams('isEnable');
        $address_arr=json_decode($address,true);
        if (empty($address_arr['street_id'])){
            $area_id=$address_arr['county_id'];
        }else{
            $area_id=$address_arr['street_id'];
        }
        $delivery_address = $this->_getContentParams('deliveryAddress');
        $delivery_address_arr=json_decode($delivery_address,true);
        if (empty($delivery_address_arr['street_id'])){
            $delivery_area_id=$delivery_address_arr['county_id'];
        }else{
            $delivery_area_id=$delivery_address_arr['street_id'];
        }
        $arr_data=[
            'mobile'=>$account,
            'real_name'=>$realName,
            'id_number'=>$idNumber,
            'start_term'=>$startTerm,
            'end_term'=>$endTerm,
            'idcard_front'=>$idcardFront,
            'idcard_back'=>$idcardBack,
            'head_portrait'=>$headPortrait,
            'express'=>$express,
            'express_branch'=>$expressBranch,
            'job_number'=>$jobNumber,
            'work_card'=>$workCard,
            'address'=>$address,
            'is_enable'=>$isEnable,
            'area_id'=>$area_id,
            'delivery_address'=>$delivery_address,
            'delivery_area_id'=>$delivery_area_id
        ];
        ModelCourierInfo::getInstance()->toUpdate("id=$courierId",$arr_data);
        _returnData();
    }

    /**
     * 快递员审核列表
     * uri:/admin/courier.audit
     */
    public function courierAudit(){
        $account = $this->_getContentParams('account');
        $realName = $this->_getContentParams('realName');
        $startTime = $this->_getContentParams('startTime');
        $endTime = $this->_getContentParams('endTime');
        $int_now_page = $this->_getContentParams('page'); // 当前页码
        if (empty($int_now_page)){
            $int_now_page = 1;
        }
        _toValidate('id', $int_now_page, 10005);

        $int_list_rows = $this->_getContentParams('listRows'); // 一页的条数
        if (empty($int_list_rows)){
            $int_list_rows = 10;
        }
        _toValidate('id', $int_list_rows, 10006);

        $sort = $this->_getContentParams('sort');
        _toCompare(empty($sort),'==',true,20012);
        //$arr_where = 'apply_for_settled.type=1';
        $arr_where = "auth_state>0 and `state`<>0 and `state`<>3";
        if (!empty($account)){
            $arr_where.=" and (courier_info.id like '%$account%' or courier_info.mobile like '%$account%')";
        }
        if (!empty($realName)){
            $arr_where.=" and courier_info.real_name like '%$realName%'";
        }
        if (!empty($startTime)){
            $arr_where.=" and DATE_FORMAT(courier_info.gmt_create,'%Y%m%d') >= DATE_FORMAT('$startTime','%Y%m%d')";
        }
        if (!empty($endTime)){
            $arr_where.=" and DATE_FORMAT(courier_info.gmt_create,'%Y%m%d') <= DATE_FORMAT('$endTime','%Y%m%d')";
        }
        $int_total_rows = ModelCourierInfo::getInstance()->toCount($arr_where);
        $int_total_pages = (int)ceil($int_total_rows / $int_list_rows);//总页数
        _toCompare(($int_now_page > $int_total_pages && $int_total_pages > 0), '===', true, 10007);
        $int_first_row = $int_list_rows * ($int_now_page - 1);//从第几条开始查询
        //$list = ModelApplyForSettled::getInstance()->getCourierAuditList($arr_where,$int_first_row,$int_list_rows,$sort);
        $list = ModelCourierInfo::getInstance()->toSelect($arr_where,"id,mobile,real_name AS realName,gmt_create AS gmtCreate,pledge_state AS pledgeState,the_number AS theNumber,auth_state AS authState",$int_first_row,$int_list_rows,"FIND_IN_SET(2,auth_state) desc,auth_state $sort,gmt_create $sort");
        _returnData(['int_total_pages'=>$int_total_pages,'list'=>$list]);
    }

    /**
     * 快递员审核详情
     * uri:/admin/courier.auditDetails
     */
    public function courierAuditDetails(){
        $courierId = $this->_getContentParams('courierId');
        _toValidate('id',$courierId,10009);
        $data = ModelCourierInfo::getInstance()->toFind("id=$courierId","auth_state AS authState,id,mobile,gmt_create AS gmtCreate,real_name AS realName,sex,birthday,address,express,job_number AS jobNumber,id_number AS idNumber,start_term AS startTerm,end_term AS endTerm,idcard_front AS idcardFront,idcard_back AS idcardBack,head_portrait AS headPortrait,to_deal_with_personnel AS toDealWithPersonnel,the_processing_time AS theProcessingTime,remark,type,pledge_state AS pledgeState");
        _returnData($data);
    }

    /**
     * 快递员审核
     * uri:/admin/courier.auditOperation
     */
    public function courierAuditOperation(){
        $type = $this->_getContentParams('type');
        $courierId = $this->_getContentParams('courierId');
        _toValidate('id',$courierId,10009);
        $remark = $this->_getContentParams('remark');
        $data = ModelCourierInfo::getInstance()->toFind("id=$courierId");
        $arr_where=[];
        if ($type==1){//通过
            $arr_where['auth_state']=1;
            $arr_where['state']=1;
            $arr_where['the_number']=intval($data['the_number'])+1;
        }elseif ($type==2){//拒绝
            $arr_where['auth_state']=3;
            $arr_where['state']=4;
            $arr_where['the_number']=intval($data['the_number'])+1;
        }
        $arr_where['remark']=$remark;
        $arr_where['to_deal_with_personnel']=ModelAdminInfo::getInstance()->toValue(['id'=>$this->admin_id],'login_account');//$this->admin_id;
        $arr_where['the_processing_time']=$this->_now;
        ModelCourierInfo::getInstance()->toUpdate("id=$courierId",$arr_where);
        _returnData();
    }

    /**
     * 快递员账号状态修改
     * uri:/admin/courier.stateChanges
     */
    public function stateChanges(){
        $courierId = intval($this->_getContentParams('courierId'));
        _toValidate('id',$courierId,15033);
        $isEnable = intval($this->_getContentParams('isEnable'));
        _toValidate('is_enable',$isEnable,10822);
        $arr_where=[
            'is_enable'=>$isEnable
        ];
        $data = ModelCourierInfo::getInstance()->toUpdate("id=$courierId",$arr_where);
        _returnData($data);
    }

    /**
     * 快递员管理数据列表导出
     * uri:/admin/courier.listExport
     */
    public function courierListExport(){
        $arr_where="";
        $str="";
        $courierId = $this->_getContentParams('courierId');
        _toValidate('id',$courierId,10009);
        $nickName = $this->_getContentParams('nickName');
        $startTime = $this->_getContentParams('startTime');
        $endTime = $this->_getContentParams('endTime');
        $str_excel = $this->_getContentParams('excel');
        $sort = $this->_getContentParams('sort');
        _toCompare(empty($sort),'==',true,20012);
        if(!empty($courierId)){
            $arr_where.=" (courier_info.id like '%$courierId%' or courier_info.mobile like '%$courierId%')";
            if (!empty($nickName) or !empty($startTime) or !empty($endTime)){
                $str=" and";
            }
        }

        if (!empty($nickName)){
            $arr_where.=" $str courier_info.real_name like '%$nickName%'";
            if (!empty($startTime) or !empty($endTime)){
                $str=" and";
            }
        }

        if (!empty($startTime)){
            $arr_where.=" $str DATE_FORMAT(courier_info.gmt_create,'%Y%m%d') >= DATE_FORMAT('$startTime','%Y%m%d')";
            if (!empty($endTime)){
                $str=" and";
            }
        }

        if (!empty($endTime)){
            $arr_where.=" $str DATE_FORMAT(courier_info.gmt_create,'%Y%m%d') <= DATE_FORMAT('$endTime','%Y%m%d')";
        }

        $list = ModelCourierInfo::getInstance()->getCourierInfo($arr_where,'','',$sort);
        if($str_excel == 'excel'){
            MobileLogicExcel::getInstance()->export($list, ['id' => '快递员ID', 'mobile' => '快递员账号', 'name' => '真实姓名', 'type' => '快递类型','closed'=>'收件总件数','send'=>'派件总件数','gmtCreate'=>'注册时间','isEnable'=>'账户启用状态(0：禁用；1：启用)'], '快递员信息列表'.date('Y-m-d', time()));
        }

        _returnData();
    }

    /**
     * 快递员订单列表导出
     * uri:/admin/courier.orderListExport
     */
    public function courierOrderListExport(){
        $type = $this->_getContentParams('type');
        $courierId = $this->_getContentParams('courierId');
        _toValidate('id',$courierId,10009);
        $str_excel = $this->_getContentParams('excel');
        $sort = $this->_getContentParams('sort');
        _toCompare(empty($sort),'==',true,20012);
        if ($type==1){
            $arr_where = '';

            $arr_where.="courier_order.courier_id=$courierId and courier_order.state in (20,30,40,70,75,80,90)";
            $orderNumber = $this->_getContentParams('orderNumber');
            $startTime = $this->_getContentParams('startTime');
            $endTime = $this->_getContentParams('endTime');
            if(!empty($orderNumber)){
                $arr_where.=" and (user_order.order_sn like '%$orderNumber%' or user_order.express_order_sn like '%$orderNumber%')";
            }

            if (!empty($startTime)){
                $arr_where.=" and DATE_FORMAT(courier_order.gmt_create,'%Y%m%d') >= DATE_FORMAT('$startTime','%Y%m%d')";
            }

            if (!empty($endTime)){
                $arr_where.=" and DATE_FORMAT(courier_order.gmt_create,'%Y%m%d') <= DATE_FORMAT('$endTime','%Y%m%d')";
            }

            $list = ModelCourierOrder::getInstance()->getCourierOrderList($arr_where,'courier_order.courier_id as courierId,courier_order.order_id as orderId,user_order.order_sn as orderSn,user_order.express_order_sn as expressOrderSn,courier_order.gmt_create as gmtCreate,user_order.order_amount as orderAmount,user_order.protect_price as protectPrice,courier_order.state','','','1',$sort);
            if($str_excel == 'excel'){
                MobileLogicExcel::getInstance()->export($list, ['courierId' => '快递员ID', 'orderId' => '订单ID', 'orderSn' => '订单编号', 'expressOrderSn' => '运单号','gmtCreate'=>'接单时间','orderAmount'=>'订单金额','protectPrice'=>'保价金额','state'=>'订单状态(75：待派件 70、20：待取件 75、30：已取件 80、40：已完成 90：已取消)','describe'=>'状态信息'], '快递员订单列表'.date('Y-m-d', time()));
            }
            _returnData();
        }elseif ($type==2){
            $arrOrderId = $this->_getContentParams('arrOrderId');
//            $str='';
//            foreach ($arrOrderId as $val){
//                $str.=$val.',';
//            }
//            $arrOrderId=rtrim($str, ",");
            $arr_where = '';
            $arr_where.="courier_order.courier_id=$courierId and courier_order.order_id in ($arrOrderId)";
//            $orderNumber = $this->_getContentParams('orderNumber');
//            $startTime = $this->_getContentParams('startTime');
//            $endTime = $this->_getContentParams('endTime');
//            if(!empty($orderNumber)){
//                $arr_where.=" and (user_order.order_sn like '%$orderNumber%' or user_order.express_order_sn like '%$orderNumber%')";
//            }
//
//            if (!empty($startTime)){
//                $arr_where.=" and DATE_FORMAT(courier_order.gmt_create,'%Y%m%d') >= DATE_FORMAT('$startTime','%Y%m%d')";
//            }
//
//            if (!empty($endTime)){
//                $arr_where.=" and DATE_FORMAT(courier_order.gmt_create,'%Y%m%d') <= DATE_FORMAT('$endTime','%Y%m%d')";
//            }

            $list = ModelCourierOrder::getInstance()->getCourierOrderList($arr_where,'courier_order.courier_id as courierId,courier_order.order_id as orderId,user_order.order_sn as orderSn,user_order.express_order_sn as expressOrderSn,courier_order.gmt_create as gmtCreate,user_order.order_amount as orderAmount,user_order.protect_price as protectPrice,courier_order.state','','','1',$sort);
            if($str_excel == 'excel'){
                MobileLogicExcel::getInstance()->export($list, ['courierId' => '快递员ID', 'orderId' => '订单ID', 'orderSn' => '订单编号', 'expressOrderSn' => '运单号','gmtCreate'=>'接单时间','orderAmount'=>'订单金额','protectPrice'=>'保价金额','state'=>'订单状态(75：待派件 70、20：待取件 75、30：已取件 80、40：已完成 90：已取消)','describe'=>'状态信息'], '快递员订单列表'.date('Y-m-d', time()));
            }
            _returnData();
        }
    }

    /**
     * 判断快递员账号、身份证号是否存在
     * uri:/admin/courier.judge
     */
    public function judge(){
        $type = $this->_getContentParams('type');
        if ($type=='account'){
            $account = $this->_getContentParams('account');
            $data = ModelCourierInfo::getInstance()->toFind("mobile=$account");
            if ($data>0){
                $judge=1;
            }else{
                $judge=0;
            }
            _returnData(['judge'=>$judge]);
        }elseif ($type=='idNumber'){
            $idNumber = $this->_getContentParams('idNumber');
            $data = ModelCourierInfo::getInstance()->toFind("id_number=$idNumber");
            if ($data>0){
                $judge=1;
            }else{
                $judge=0;
            }
            _returnData(['judge'=>$judge]);
        }
    }

    /**
     * 添加快递员
     * uri:/admin/courier.add
     */
    public function courierAdd(){
        $account = $this->_getContentParams('account');
        $realName = $this->_getContentParams('realName');
        $idNumber = $this->_getContentParams('idNumber');
        $startTerm =$this->_getContentParams('startTerm');
        $endTerm = $this->_getContentParams('endTerm');
        $idcardFront = $this->_getContentParams('idcardFront');
        $idcardBack = $this->_getContentParams('idcardBack');
        $headPortrait = $this->_getContentParams('headPortrait');
        $express = $this->_getContentParams('express');
        $expressBranch = $this->_getContentParams('expressBranch');
        $jobNumber = $this->_getContentParams('jobNumber');
        $workCard = $this->_getContentParams('workCard');
        $address = $this->_getContentParams('address');
        $isEnable = $this->_getContentParams('isEnable');
        $str_pwd_key = $this->_getRandomString(8);
        $password = passwordEncryption('123456', $str_pwd_key);
        $address_arr=json_decode($address,true);
        if (empty($address_arr['street_id'])){
            $area_id=$address_arr['county_id'];
        }else{
            $area_id=$address_arr['street_id'];
        }
        $delivery_address = $this->_getContentParams('deliveryAddress');
        $delivery_address_arr=json_decode($delivery_address,true);
        if (empty($delivery_address_arr['street_id'])){
            $delivery_area_id=$delivery_address_arr['county_id'];
        }else{
            $delivery_area_id=$delivery_address_arr['street_id'];
        }
        $arr_data=[
            'mobile'=>$account,
            'real_name'=>$realName,
            'id_number'=>$idNumber,
            'start_term'=>$startTerm,
            'end_term'=>$endTerm,
            'idcard_front'=>$idcardFront,
            'idcard_back'=>$idcardBack,
            'head_portrait'=>$headPortrait,
            'express'=>$express,
            'express_branch'=>$expressBranch,
            'job_number'=>$jobNumber,
            'work_card'=>$workCard,
            'address'=>$address,
            'is_enable'=>$isEnable,
            'password'=>$password,
            'pwd_key'=>$str_pwd_key,
            'area_id'=>$area_id,
            'delivery_address'=>$delivery_address,
            'delivery_area_id'=>$delivery_area_id
        ];
        $data = ModelCourierInfo::getInstance()->toAdd($arr_data);
        _returnData($data);
    }

    /**
     * 快递员审核列表导出
     * uri:/admin/courier.auditListExport
     */
    public function courierAuditListExport(){
        $str_excel = $this->_getContentParams('excel');
        $type = $this->_getContentParams('type');
        $sort = $this->_getContentParams('sort');
        _toCompare(empty($sort),'==',true,20012);
        $arr_where='';
        if ($type==1){
            $account = $this->_getContentParams('account');
            $realName = $this->_getContentParams('realName');
            $startTime = $this->_getContentParams('startTime');
            $endTime = $this->_getContentParams('endTime');
            $arr_where = "auth_state>0 and `state`<>0 and `state`<>3";
            if (!empty($account)){
                $arr_where.=" and (courier_info.id like '%$account%' or courier_info.mobile like '%$account%')";
            }
            if (!empty($realName)){
                $arr_where.=" and courier_info.real_name like '%$realName%'";
            }
            if (!empty($startTime)){
                $arr_where.=" and DATE_FORMAT(courier_info.gmt_create,'%Y%m%d') >= DATE_FORMAT('$startTime','%Y%m%d')";
            }
            if (!empty($endTime)){
                $arr_where.=" and DATE_FORMAT(courier_info.gmt_create,'%Y%m%d') <= DATE_FORMAT('$endTime','%Y%m%d')";
            }
        }elseif ($type==2){
            $arrCourierId = $this->_getContentParams('arrCourierId');
            $arr_where.="courier_info.id in ($arrCourierId)";
        }
        $list = ModelCourierInfo::getInstance()->toSelect($arr_where,"id,mobile,real_name AS realName,gmt_create AS gmtCreate,pledge_state AS pledgeState,the_number AS theNumber,state",'','',"FIND_IN_SET(2,auth_state) desc,auth_state $sort,gmt_create $sort");
        if ($str_excel=='excel'){
            MobileLogicExcel::getInstance()->export($list, ['id' => '快递员ID', 'mobile' => '快递员账号', 'realName' => '真实姓名', 'gmtCreate' => '注册时间','pledgeState'=>'押金情况','theNumber'=>'审核次数','authState'=>'审核状态（1：已通过 2：待审核 3：已拒绝）'], '快递员审核'.date('Y-m-d', time()));
        }
        _returnData();
    }

    /**
     * 快递员管理-》密码重置
     * uri:/admin/courier.passwordReset
     */
    public function courierPasswordReset(){
        $courierId = $this->_getContentParams('courierId');
        _toValidate('id',$courierId,20019);
        $str_pwd_key = $this->_getRandomString(8);
        $password = passwordEncryption('123456', $str_pwd_key);
        $arr_where=[
            'password'=>$password,
            'pwd_key'=>$str_pwd_key
        ];
        $data = ModelCourierInfo::getInstance()->toUpdate("id=$courierId",$arr_where);
        if ($data>0){
            _returnData();
        }
    }
}